# coding=utf-8
"""
Author: Mr.夏末
@Function: 排序库：模块化封装
"""
import sys

from class06.package_demo.decs import mytime_new

@mytime_new()
def choose(params):
    for j in range(len(params) - 1):
        maxindex = 0
        for i in range(1, len(params) - j):
            if params[i] > params[maxindex]:
                maxindex = i
        params[maxindex], params[len(params) - 1 - j] = params[len(params) - 1 - j], params[maxindex]
    # gi = 0
    # while gi < len(params) - 1:
    #     kmax = 0
    #     ki = 1
    #     while ki < len(params) - gi:
    #         if params[ki] > params[kmax]:
    #             kmax = ki
    #         ki += 1
    #     params[kmax], params[len(params) - 1 - gi] = params[len(params) - 1 - gi], params[kmax]
    #     gi += 1
@mytime_new()
def bubbling(params):
    for j in range(len(params) - 1):
        for i in range(0, len(params) - 1 - j):
            if params[i] > params[i + 1]:
                params[i], params[i + 1] = params[i + 1], params[i]
    # kindex = 0
    # while kindex < len(params) - 1:
    #     index = 0
    #     while index < len(params) - 1 - kindex:
    #         if params[index] > params[index + 1]:
    #             params[index], params[index + 1] = params[index + 1], params[index]
    #         index += 1
    #     kindex += 1

def speediness(params,left,right):
    base = params[right]
    l = left
    h = right
    while l < h:
        while l < h:
            if params[l] > base:
                params[l], params[h] = params[h], params[l]
                h -= 1
                break
            else:
                l += 1
        while l < h:
            if params[h] < base:
                params[l], params[h] = params[h], params[l]
                l += 1
                break
            else:
                h -= 1
    if l - 1 -left >0:
        speediness(params,left,l-1)
    if right - h -1 > 0:
        speediness(params, h+1, right)

if __name__ == '__main__':
    params = [i for i in range(1000)]
    bubbling(params)
    # print(params)
    print("--------------------------")
    choose(params)
    # print(params)
    print("--------------------------")
    params = [185, 175, 165, 190, 180, 185, 170, 175, 160, 165, 155, 150, 145, 140, 135, 130, 200, 120, 195, 165, 100, 185]
    # 修改默认堆栈大小
    sys.setrecursionlimit((1000000))
    speediness(params, 0, len(params) - 1)
    print(params)